package com.sinothk.gpserver.connection.websocket.bean;

import com.alibaba.fastjson.JSON;
import com.sinothk.gpserver.data.WsConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 编写 Liang Y.T.
 * 时间 2021/6/27 19:52
 */
@ApiModel("消息体")
@Data
public class Message implements Serializable {

    public static final int TYPE_BROADCAST = 0;
    public static final int TYPE_PERSON = 1;
    public static final int TYPE_ROOM = 2;
    public static final int TYPE_GROUP = 3;
    public static final int TYPE_CLUB = 5;

    @ApiModelProperty("消息类型：0广播/1个人/2房间/3群组/5俱乐部")
    private int type;

    @ApiModelProperty("消息内容")
    private String body;

    public static Message getPersonMsg(PersonMsg personMsg) {
        Message message = new Message();
        message.setType(WsConstant.MsgType.TYPE_PERSON);
        message.setBody(JSON.toJSONString(personMsg));
        return message;
    }

    public static Message getPersonMsg(String jsonBodyStr) {
        Message message = new Message();
        message.setType(WsConstant.MsgType.TYPE_PERSON);
        message.setBody(jsonBodyStr);//
        return message;
    }
}
